home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr01 / halcn305.zip / GSDMO_12.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-02  |  4KB  |  112 lines

  1. program GSDMO_12;
  2. {------------------------------------------------------------------------------
  3.                          DBase Relational File Linkage
  4.  
  5.        Copyright (c)  Richard F. Griffin
  6.  
  7.        20 Janmuary 1993
  8.  
  9.        102 Molded Stone Pl
  10.        Warner Robins, GA  31088
  11.  
  12.        -------------------------------------------------------------
  13.        This unit demonstrates how to link the relationships between
  14.        dBase files for data retrieval based on common fields in two files.
  15.  
  16.        The master file index is on the UNIQUEID field.  This will be used
  17.        to get the master record based on the MASTERID field in the
  18.        transaction record.
  19.  
  20.        The routine will read each transaction and display transaction
  21.        information.  It will then find the correct master record and
  22.        display master information.
  23.  
  24.        New procedures/functions introduced are:
  25.  
  26.                  Found
  27.                  Strip_Flip
  28.  
  29. -------------------------------------------------------------------------------}
  30.  
  31. uses
  32.    GSOB_Str,
  33.    GSOBShel,
  34.    {$IFDEF WINDOWS}
  35.       WinCRT,
  36.       WinDOS;
  37.    {$ELSE}
  38.       CRT,
  39.       DOS;
  40.    {$ENDIF}
  41.  
  42.  
  43. var
  44.    ch : char;
  45.    mfileid : string[8];
  46.  
  47. begin
  48.    ClrScr;
  49.    ch := ' ';
  50.  
  51.    if not FileExist('GSDMO_MF.DBF') then
  52.    begin
  53.       writeln('File GSDMO_MF.DBF not found.  Run GSDMO_11 to create.');
  54.       halt;
  55.    end;
  56.  
  57.    if not FileExist('GSDMO_TF.DBF') then
  58.    begin
  59.       writeln('File GSDMO_TF.DBF not found.  Run GSDMO_11 to create.');
  60.       halt;
  61.    end;
  62.  
  63.                        {The 'Real' example starts here}
  64.  
  65.    Select(1);                          {Assign master file area}
  66.    Use('GSDMO_MF');
  67.    Index('GSDMO_ID');                  {Use the UNIQUEID key index}
  68.    Select(2);                          {Switch to the transaction file area}
  69.    Use('GSDMO_TF');
  70.    GoTop;                              {Get the first transaction record}
  71.    while not (dEOF) and (Ch <> #27) do {ESC will also end the run (#27)}
  72.    begin
  73.       ClrScr;
  74.       mfileid := FieldGet('MASTERID');
  75.                        {Display transaction information}
  76.  
  77.       Writeln('':34,'TRANSACTION');
  78.       Writeln;
  79.       Writeln('  FULLNAME : ',Strip_Flip(StringGet('FULLNAME')));
  80.       Writeln('  TRANDATE : ',DTOC(DateGet('TRANDATE')));
  81.       Writeln('    AMOUNT : ',FieldGet('AMOUNT'));
  82.       Writeln('   PAYTYPE : ',FieldGet('PAYTYPE'));
  83.       Writeln;
  84.       Writeln('':20,'-----------------------------------------');
  85.       Writeln('':37,'MASTER');
  86.       Writeln;
  87.  
  88.                  {Now, go find the master record}
  89.  
  90.       Select(1);                   {Switch to the master file}
  91.       Find(mfileid);               {Find the UNIQUEID key in the master file}
  92.                                    {that matches the transaction MASTERID}
  93.       if Found then                {Test for successful Find}
  94.       begin
  95.          Writeln('  LASTNAME : ',FieldGet('LASTNAME'));
  96.          Writeln(' FIRSTNAME : ',FieldGet('FIRSTNAME'));
  97.          Writeln('    STREET : ',FieldGet('STREET'));
  98.          Writeln('   ADDRESS : ',StringGet('CITY'),', ',
  99.                                  FieldGet('STATE'),' ',
  100.                                  FieldGet('ZIP'));
  101.       end
  102.       else writeln('Cannot Find the Master Record!');
  103.  
  104.       Writeln;
  105.       Writeln('Press Any Key to Continue: ') ;
  106.       Writeln('[ESC] Will Terminate the Program');
  107.       ch := ReadKey;
  108.       Select(2);                       {Go back to the transaction}
  109.       Skip(1);                         {and get the next record}
  110.    end;
  111.    CloseDataBases;
  112. end.